package me.shurufa;


import android.app.Application;

import com.umeng.socialize.PlatformConfig;

import java.util.ArrayList;
import java.util.List;

import cn.finalteam.okhttpfinal.OkHttpFinal;
import cn.finalteam.okhttpfinal.OkHttpFinalConfiguration;
import cn.finalteam.okhttpfinal.Part;
import me.shurufa.utils.Constants;
import me.shurufa.utils.Global;
import me.shurufa.utils.ShareConstants;
import okhttp3.Headers;
import okhttp3.Interceptor;

/**
 * 单例Application
 *
 * @FileName: me.shurufa.MainApplication.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-14 12:30
 */
public class MainApplication extends Application {

    private static MainApplication sInstance;

    public static MainApplication getInstance() {
        return sInstance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
        //Global.DEBUG = true;

        initOkHttpFinal();
        initShare();
        //CustomActivityOnCrash.install(this);
    }


    private void initShare() {
        // 微信 appid appsecret
        PlatformConfig.setWeixin(ShareConstants.WX_ID, ShareConstants.WX_SECRECT);
        // 新浪微博 appkey appsecret
        PlatformConfig.setSinaWeibo(ShareConstants.WB_ID, ShareConstants.WB_SECRECT);
        // QQ Qzone appkey appsecret
        //PlatformConfig.setQQZone(ShareConstants.QQ_ID, ShareConstants.QQ_SECRECT);
        PlatformConfig.setQQZone("1105325306", "yH6OHbQiWCSDGlnE");
    }

    private void initOkHttpFinal() {

        List<Part> commomParams = new ArrayList<>();
        Headers commonHeaders = new Headers.Builder().build();

        List<Interceptor> interceptorList = new ArrayList<>();
        OkHttpFinalConfiguration.Builder builder = new OkHttpFinalConfiguration.Builder()
                .setCommenParams(commomParams)
                .setCommenHeaders(commonHeaders)
                .setTimeout(Constants.REQ_TIMEOUT)
                .setInterceptors(interceptorList)
                //.setCookieJar(CookieJar.NO_COOKIES)
                //.setCertificates(...)
                //.setHostnameVerifier(new SkirtHttpsHostnameVerifier())
                .setDebug(Global.DEBUG);
//        addHttps(builder);
        OkHttpFinal.getInstance().init(builder.build());
    }


}
